home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / VideoToolbox / VideoToolboxSources / StringToDate.c < prev    next >
Text File  |  1993-02-23  |  1KB  |  45 lines

  1. /*
  2. StringToDate.c
  3. Reads date such as "6/30/91", loads date structure, and returns secs since 1/1/1904.
  4. Returns NAN if date could not be read.
  5.  
  6. HISTORY:
  7. 7/27/91 dgp    wrote it
  8. 8/5/91    dgp    made compatible with MPW C 3.2
  9. 8/24/91    dgp    Made compatible with THINK C 5.0.
  10. 12/13/92 dgp Removed obsolete support for THINK C 4.
  11. */
  12. #include "VideoToolbox.h"
  13. #include <Script.h>
  14.  
  15. double StringToDate(char *string,DateTimeRec *datePtr);
  16.  
  17. double StringToDate(char *string,DateTimeRec *datePtr)
  18. {
  19.     LongDateRec longDate;
  20.     LongDateCvt longSecs;
  21.     double secs;
  22.     static DateCacheRecord theCache;
  23.     static Boolean firstTime=1;
  24.     int error;
  25.     long used;
  26.     
  27.     longDate.ld.era=longDate.ld.year=longDate.ld.month=longDate.ld.day=0;
  28.     longDate.ld.hour=longDate.ld.minute=longDate.ld.second=longDate.ld.dayOfWeek=0;
  29.     if(firstTime){
  30.         InitDateCache(&theCache);
  31.         firstTime=0;
  32.     }
  33.     error=String2Date(string,strlen(string),&theCache,&used,&longDate);
  34.     *datePtr=longDate.od.oldDate;
  35.     if(error)return 0./0.;
  36.     LongDate2Secs(&longDate,(LongDateTime *)&longSecs);
  37.     secs=HiWord(longSecs.hl.lHigh);
  38.     secs*=(double)0x10000;
  39.     secs+=(unsigned)LoWord(longSecs.hl.lHigh);
  40.     secs*=(double)0x10000;
  41.     secs+=(unsigned)HiWord(longSecs.hl.lLow);
  42.     secs*=(double)0x10000;
  43.     secs+=(unsigned)LoWord(longSecs.hl.lLow);
  44.     return secs;
  45. }